import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../common_ui/confirm_btn.dart';
import '../../const/common_const.dart';
import '../../style/box_style.dart';
import '../../style/color_style.dart';
import '../../style/edgeInsets_style.dart';
import '../../style/radius_style.dart';
import '../../style/text_style.dart';
import '../controller/password_login_controller.dart';

class PasswordLoginPage extends StatefulWidget {
  const PasswordLoginPage({super.key});

  @override
  State<PasswordLoginPage> createState() => _PasswordLoginPageState();
}

class _PasswordLoginPageState extends State<PasswordLoginPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(backgroundColor: ColorStyle.themeColor,body: GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () {
              // 点击空白区域时收起键盘
              FocusScope.of(context).unfocus();
            },
            child: GetBuilder<PassWordLoginController>(
              init: PassWordLoginController(),
              builder: (controller) {
                return CustomScrollView(slivers: [
                  // 输入框
                  inputWidget(controller),
                  loginBtnWidget(controller),
                ]);
              },
            )));
  }

  Widget inputWidget(PassWordLoginController controller) {
    return SliverToBoxAdapter(
        child: Container(
            decoration: BoxDecoration(
              borderRadius: RadiusStyle.radiusAll(14),
              color: ColorStyle.whiteColor,
            ),
            margin: EdgeInsetsStyle.customMargin(20, 110, 20, 0),
            padding: EdgeInsetsStyle.customMargin(30, 50, 20, 74),
            child: Column(
              children: [
                // 手机号
                Container(
                  height: 44.h,
                  padding: EdgeInsetsStyle.edgeInsets(20, 0),
                  decoration: BoxDecoration(
                      borderRadius: RadiusStyle.radiusAll(25),
                      color: const Color(0xFFF5F7F7)),
                  child: Row(children: [
                    Expanded(
                        child: TextField(
                      controller: controller.phoneController,
                      keyboardType: TextInputType.number,
                      textInputAction: TextInputAction.next,
                      decoration: const InputDecoration(
                        hintText: LoginStringConst.inputPhoneHintText,
                        border: InputBorder.none,
                      ),
                    ))
                  ]),
                ),
                Box.vBox10,
                
                Text.rich(TextSpan(children: [
        TextSpan(
          text: LoginStringConst.registerPrefix,
          style: Styles.greyText_12,
        ),
        TextSpan(text: LoginStringConst.registerText, style: Styles.blueText_12,recognizer: TapGestureRecognizer()
          ..onTap = () {
            controller.registerClick();
          }),
      ])),
                Box.vBox14,
                // 验证码
                Container(
                  height: 44.h,
                  padding: EdgeInsetsStyle.edgeInsets(20, 0),
                  decoration: BoxDecoration(
                      borderRadius: RadiusStyle.radiusAll(25),
                      color: const Color(0xFFF5F7F7)),
                  child: Row(children: [
                    Expanded(
                        child: TextField(
                      controller: controller.passwordController,
                      keyboardType: TextInputType.number,
                      textInputAction: TextInputAction.next,
                      decoration: const InputDecoration(
                        hintText: LoginStringConst.inputPassWordText,
                        border: InputBorder.none,
                      ),
                    )),
                    
                  ]),
                ),
                Box.vBox20,
                Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
                  GestureDetector(
                    child: Text(
                      LoginStringConst.codeLoginText,
                      style: Styles.mainText_14,
                    ),
                    onTap: () {
                      controller.backCodeLogin();
                    },
                  ),
                  
                  GestureDetector(
                    child: Text(
                      LoginStringConst.forgetPasswordText,
                      style: Styles.mainText_14,
                    ),
                    onTap: () {
                      controller.forgetClick();
                    },
                  ),
                ],)
              ],
            )));
  }

  Widget loginBtnWidget(PassWordLoginController controller) {
    return SliverToBoxAdapter(
        child: Container(
            margin: EdgeInsetsStyle.customMargin(20, 110, 20, 0),
            child: ConfirmButton(
              title: LoginStringConst.loginText,
              callBack: () {
                // controller.loginClick();
              },
            )));
  }
}